package aos.maekawa.entity;

import java.io.Serializable;

public class ReportData implements Serializable {

	private static final long serialVersionUID = 1L;
	private int nodeId;
	private int requestNum;
	private int replyNum;
	private int releaseNum;
	private int failNum;
	private int enquireNum;
	private int yieldNum;

	public ReportData(int nodeId) {
		setNodeId(nodeId);
		setRequestNum(0);
		setReplyNum(0);
		setReleaseNum(0);
		setFailNum(0);
		setEnquireNum(0);
		setYieldNum(0);
	}

	public synchronized void processMsg(boolean isReceive, Message msg) {
		if (msg.getFromId() == msg.getToId()) {
			return;
		}
		if (isReceive) {
			switch (msg.getMsgType()) {
			case REPLY:
				increaseReplyNum();
				break;
			case FAIL:
				increaseFailNum();
				break;
			case ENQUIRE:
				increaseEnquireNum();
				break;
			default:
			}
		} else {
			switch (msg.getMsgType()) {
			case REQUEST:
				increaseRequestNum();
				break;
			case RELEASE:
				increaseReleaseNum();
				break;
			case YIELD:
				increaseYieldNum();
				break;
			default:
			}
		}
	}

	public String toString() {
		return "nodeId: " + nodeId + " requestNum(sent): " + requestNum
				+ " replyNum(recv): " + replyNum + " releaseNum(sent): "
				+ releaseNum + " failNum(recv): " + failNum
				+ " enquireNum(recv): " + enquireNum + " yieldNum(sent): "
				+ yieldNum;
	}

	public void dump() {
		System.out.println(toString());
	}

	public int getRequestNum() {
		return requestNum;
	}

	public void setRequestNum(int requestNum) {
		this.requestNum = requestNum;
	}

	public void increaseRequestNum() {
		this.requestNum++;
	}

	public int getReleaseNum() {
		return releaseNum;
	}

	public void setReleaseNum(int releaseNum) {
		this.releaseNum = releaseNum;
	}

	public void increaseReleaseNum() {
		this.releaseNum++;
	}

	public int getReplyNum() {
		return replyNum;
	}

	public void setReplyNum(int replyNum) {
		this.replyNum = replyNum;
	}

	public void increaseReplyNum() {
		this.replyNum++;
	}

	public int getFailNum() {
		return failNum;
	}

	public void setFailNum(int failNum) {
		this.failNum = failNum;
	}

	public void increaseFailNum() {
		this.failNum++;
	}

	public int getYieldNum() {
		return yieldNum;
	}

	public void setYieldNum(int yieldNum) {
		this.yieldNum = yieldNum;
	}

	public void increaseYieldNum() {
		this.yieldNum++;
	}

	public int getEnquireNum() {
		return enquireNum;
	}

	public void setEnquireNum(int enquireNum) {
		this.enquireNum = enquireNum;
	}

	public void increaseEnquireNum() {
		this.enquireNum++;
	}

	public int getNodeId() {
		return nodeId;
	}

	public void setNodeId(int nodeId) {
		this.nodeId = nodeId;
	}

}
